import rbacSys from './sys.config.js'

export default {
    uploadUrl() { // 获取上传地址
        return rbacSys.defaults.baseURL + "/user/upload" ;
    },
    login(username, password) {
        return rbacSys.post("/api/token", {username, password}, {
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            }
        })
    },
    refresh(refreshToken) {
        return rbacSys.put("/api/token", {refresh:refreshToken}, {
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            }
        })
    },
    // 添加系统
    addSystem({sysName, url, description, state, remark}) {
        return rbacSys.post("/sys/add", {sysName, url, description, state,remark}) ;
    },
    // 更新系统
    updateSystem({id, sysName, url, description, state, remark}) {
        return rbacSys.put("/sys/update/" + id, {sysName, url, description, state,remark}) ;
    },
    // 根据系统名检查是否可用
    checkSystemName(sysName) {
        return rbacSys.get("/sys/check/" + sysName) ;
    },
    // 查询所有系统
    queryAllSys() {
        return rbacSys.get("/sys/list");
    },
    // 根据系统ID 删除系统
    delSys(id) {
        return rbacSys.delete("/sys/del/" + id);
    },
    // 批量删除多个系统
    batchDelSys(...ids) {
        return rbacSys.delete("/sys/batch", {data: ids });
    },
    // 添加菜单
    addMenu({menuName, icon, sort, description, state}) {
        return rbacSys.post("/menu/add", {menuName, icon, sort, description, state}) ;
    },
    // 修改菜单
    updateMenu({id, menuName, icon, sort, description, state}) {
        return rbacSys.put("/menu/update/" + id, {menuName, icon, sort, description, state}) ;
    },
    // 分页查询菜单
    queryMenusByPage({page, rows, name, state}) {
        return rbacSys.get("/menu/list", {
            params: {page, rows, name, state}
        })
    },
    // 根据菜单ID 查询系统列表
    queryMenuBindSysList(menuId) {
        return rbacSys.get("/sys/menuBindSysList/" + menuId);
    },
    // 根据系统ID 查询菜单列表
    querySysBindMenuList(sysId) {
        return rbacSys.get("/menu/sysBindMenuList/" + sysId);
    },
    // 菜单绑定系统
    bindSysByMenuId(menuId, sysIds) {
        return rbacSys.put("/menu/bindSys/" + menuId,  sysIds) ;
    },
    // 系统绑定菜单
    bindMenusBySysId(sysId, menuIds) {
        return rbacSys.put("/sys/bindMenu/" + sysId,  menuIds) ;
    },
    // 批量删除多个系统
    batchDelMenu(...ids) {
        return rbacSys.delete("/menu/batch", {data: ids });
    },
    // 根据菜单ID 删除菜单
    delMenu(id) {
        return rbacSys.delete("/menu/del/" + id);
    },
    // 查询所有的功能列表
    queryAllFunc({page, rows, ...search}) {
        return rbacSys.get("/func/list" , {
            params: {page, rows, ...search}
        });
    },
    addFunc({funcName, url, state, remark, menus, sorted}) {
        return rbacSys.post("/func/add" , {funcName, url, state, remark, menus, sorted})
    },
    updateFunc({id, funcName, url, state, remark, menus, sorted}) {
        return rbacSys.put("/func/update/" + id , {funcName, url, state, remark, menus, sorted})
    },
    queryMenusRefFunc(funcId) {
        return rbacSys.get("/func/queryMenusRefFunc", {
            params: funcId == null ? {} : {funcId}
        })
    },
    batchDelFunc(funcIds) {
        return rbacSys.delete("/func/batchDelete" , {data: funcIds});
    },
    delFunc(funcId) {
        return rbacSys.delete("/func/del/" + funcId) ;
    },
    queryBtnsByFuncId(funcId) {
        return rbacSys.get("/btn/list/" + funcId);
    },
    addBtn({btnName, remark, state, funcId}) {
        return rbacSys.post("/btn/add", {btnName, remark, state, funcId}) ;
    },
    updateBtn({id, btnName, remark, state, funcId}) {
        return rbacSys.put("/btn/update/" + id, {btnName, remark, state, funcId}) ;
    },
    delBtn(btnId) {
        return rbacSys.delete("/btn/del/" + btnId) ;
    },
    addOrganization({name, code, state, pid}) {
        return rbacSys.post("/org/add" , {name, code, state, pid}) ;
    },
    updateOrganization({id, name, code, state, pid}) {
        return rbacSys.put("/org/update/" + id , {name, code, state, pid}) ;
    },
    queryOrganizationList() {
        return rbacSys.get("/org/list");
    },
    queryUsersByOrganization(orgId) {
        return rbacSys.get("/org/"+ orgId +"/users/") ;
    },
    deleteOrganization(orgId) {
        return rbacSys.delete("/org/del/" + orgId);
    },
    queryPositions({page, rows, name, state} = {}) {
        return rbacSys.get("/position/list" , {params: {page, rows, name, state}})
    },
    batchDelPosition(ids) {
        return rbacSys.delete("/position/batchDel" , {data:ids })
    },
    deletePosition(id) {
        return rbacSys.delete("/position/del/" + id)
    },
    savePosition({name, description, state}) {
        return rbacSys.post("/position/add", {name, description, state})
    },
    updatePosition({id, name, description, state}) {
        return rbacSys.put("/position/update/" + id, {name, description, state})
    },
    queryOrgAndPositionOrUserData(userId) { // 查询组织机构信息、职务信息 或 用户详情信息
        return rbacSys.get("/user/queryOrgAndPositionOrUserData", {params: {userId}}) ;
    },
    addUser({username, password, realName, tel, orgs, email, positions, sex, birth, state, avatar}) {
        return rbacSys.post("/user/add" , {username, password, realName, tel, orgs, email, positions, sex, birth, state, avatar}) ;
    },
    updateUser({id, username, password, realName, tel, orgs, email, positions, sex, birth, state, avatar}) {
        return rbacSys.put("/user/update/" + id , {username, password, realName, tel, orgs, email, positions, sex, birth, state, avatar}) ;
    },
    queryUserList({page, rows, time, ...search} = {}) {
        // time 结构出来的目的是为了 search 中不包含该参数
        return rbacSys.get("/user/list", {
            params: {
                page, rows, ...search
            }
        });
    },
    deleteUser(userId) {
        return rbacSys.delete("/user/del/" + userId);
    },

    addRole({name, defaultRole, description, remark, state}) {
        return rbacSys.post("/role/add" , {name, defaultRole, description, remark, state}) ;
    },
    updateRole({id, name, defaultRole, description, remark, state}) {
        return rbacSys.put("/role/update/" + id , {name, defaultRole, description, remark, state}) ;
    },
    queryRoleList({page, rows, ...search} = {}) {
        // time 结构出来的目的是为了 search 中不包含该参数
        return rbacSys.get("/role/list", {
            params: {
                page, rows, ...search
            }
        });
    },
    deleteRole(roleId) {
        return rbacSys.delete("/role/delete/" + roleId);
    },
    batchDeleteRoles(roleIds) {
        return rbacSys.delete("/role/batchRemove" , {data: roleIds});
    },
    queryUserBindRoles(userId) {
        return rbacSys.get("/user/"+ userId +"/roles");
    },
    bindRole(userId, roles) {
        return rbacSys.put("/user/" + userId + "/bindRole" , roles) ;
    },
    queryPermissionTree(roleId) {
        return rbacSys.get("/role/"+ roleId +"/queryPermissionTree")
    },
    savePermission(roleId, nodes) {
        return rbacSys.post("/role/" + roleId + "/bindPermission", nodes) ;
    },

    queryServiceLoggers(page, rows, search) {
        return rbacSys.get("/log/list", {
            params: {
                page, rows, ...search
            }
        });
    },
    querySignLogs(page, rows, search) {
        return rbacSys.get("/log/signs", {
            params: {
                page, rows, ...search
            }
        });
    },

    querySwipers() {
        return rbacSys.get("/swiper/list") ;
    },
    updateSwiperPath() {
        return rbacSys.defaults.baseURL + "/swiper/upload" ;
    },
    previewPath(name) {
        return rbacSys.defaults.baseURL + "/preview?path=" + name + "&type=inline";
    },
    saveSwiper({sysId, url, linkUrl, state}) {
        return rbacSys.post("/swiper/add", {sysId, url, linkUrl, state}) ;
    },
    updateSwiper({id, sysId, url, linkUrl, state}) {
        return rbacSys.put("/swiper/update/" + id , {id, sysId, url, linkUrl, state}) ;
    },
    removeSwiper(id) {
        return rbacSys.delete("/swiper/" + id) ;
    },

    batchRemoveSwiper(ids) {
        return rbacSys.delete("/swiper" , {data: ids})
    },

    queryAdverts() {
        return rbacSys.get("/advert/list") ;
    },
    updateAdvertPath() {
        return rbacSys.defaults.baseURL + "/advert/upload" ;
    },
    saveAdvert({sysId, url, linkUrl, state}) {
        return rbacSys.post("/advert/add", {sysId, url, linkUrl, state}) ;
    },
    updateAdvert({id, sysId, url, linkUrl, state}) {
        return rbacSys.put("/advert/update/" + id , {id, sysId, url, linkUrl, state}) ;
    },
    removeAdvert(id) {
        return rbacSys.delete("/advert/" + id) ;
    },

    batchRemoveAdvert(ids) {
        return rbacSys.delete("/advert" , {data: ids})
    },
}